﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using UMLObjects;
using System.ComponentModel;
using System.Runtime.Serialization;


namespace WIN_UML_Editor
{
    // Singleton
    public class UMLFocus : INotifyPropertyChanged
    {
        private static UMLFocus instance = new UMLFocus();
        private static IUMLUC focusObject;
        public event PropertyChangedEventHandler PropertyChanged;
        
        // Private constructor, can't be called outside the class
        private UMLFocus() {  }

        public static UMLFocus Instance
        {
            get { return instance; }
        }

        //Get/Set focus object
        public IUMLUC Object
        {
            get { return focusObject; }
            set {
                if(focusObject != null)
                    focusObject.deselect();

                focusObject = value;

                if(focusObject != null)
                    focusObject.select();

                NotifyPropertyChanged("Object");
                NotifyPropertyChanged("Name");
            }
        }

        //Get/Set name
        public string Name
        {
            get { 
                if (focusObject == null) 
                    return "Select Object..."; 
                else 
                    return focusObject.ObjName; 
            }
            set {
                if (focusObject != null)
                    focusObject.ObjName = value;
            }
        }

        private void NotifyPropertyChanged(String info)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(info));
            }
        }
    }
}
